home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Scheduling / Cassandra / Source / EditEvent.m < prev    next >
Encoding:
Text File  |  1991-11-01  |  8.9 KB  |  420 lines

  1. //
  2. // EditEvent.m
  3. // Copyright (c) 1989, 1990 by Jiro Nakamura 
  4. // All rights reserved
  5. //
  6. // This is the control object that handles the window that allows the user to
  7. // edit Cassandra's database
  8. //
  9. // RCS Information
  10. // Revision Number->    $Revision: 2.3 $
  11. // Last Revised->    $Date: 91/11/01 17:23:11 $
  12. //
  13. char rcsid[] = "$Id: EditEvent.m,v 2.3 91/11/01 17:23:11 jiro Exp Locker: jiro $";
  14.  
  15. #import <appkit/Form.h>
  16. #import <appkit/Button.h>
  17. #import <appkit/Matrix.h>
  18. #import <appkit/Panel.h>           /* for NXRunAlertPanel() */
  19. #import <appkit/publicWraps.h>  /* for NXBeep( )     */
  20.  
  21. #import "calendar.h"
  22. #import "Event.h"
  23. #import "Global.h"
  24. #import "EditEvent.h"
  25. #import "Cassandra.h"
  26.  
  27. @implementation EditEvent
  28. - open: sender
  29. {
  30.     ev = [Event newAt: [global eventFile]];
  31.     [ev firstEvent];
  32.     [hereForm setIntValue: [ev present] at:0];    
  33.     
  34.     [self readEvent:self];
  35.     return self;
  36. }
  37.  
  38. - readEvent:sender
  39. {
  40.     EFileLink here, previous, next;
  41.     
  42.     here = [hereForm intValueAt:0];
  43.     if( here < 0)
  44.         {
  45.         NXRunAlertPanel("File Read Error", 
  46.             "Sorry, you can't read from negative event numbers.",
  47.             "Ahh..", NULL,NULL);
  48.         return self;
  49.         }
  50.  
  51.     [ev readEvent : here];
  52.     next = [ev next];
  53.     previous = [ev previous];
  54.  
  55.     if( ![global guru])
  56.         {
  57.         if( here == 0)
  58.             NXRunAlertPanel("Warning",
  59.                 "You are reading event 0. "
  60.                 "It is where important event linking and "
  61.                 "global information is kept. Be very careful "
  62.                 "when modifying any of the variables in it.",
  63.                 "OK",NULL,NULL);
  64.         
  65.         if( next == -1 || previous == -1)
  66.             NXRunAlertPanel("Warning",
  67.                 "This is a deleted event. The values in it "
  68.                 "are now meaningless.","OK",NULL,NULL);
  69.         }
  70.         
  71.     vHere = here;
  72.     vNow = *[ev time];
  73.     
  74.     [nextForm    setIntValue    : next];
  75.     [previousForm    setIntValue    : previous];
  76.     if( [global guru])
  77.         {
  78.         [nextForm    setEnabled:    TRUE];
  79.         [previousForm    setEnabled:    TRUE];
  80.         }
  81.     else
  82.         {
  83.         [nextForm    setEnabled:    FALSE];
  84.         [previousForm    setEnabled:    FALSE];
  85.         }
  86.         
  87.     [self displayValues: self];
  88.     
  89.     [hereForm selectTextAt:0];    
  90.     return self;
  91. }
  92.  
  93.  
  94. - writeEvent:sender
  95. {
  96.     int here, previous, next, vAnniv;
  97.     
  98.     here = [hereForm intValueAt:0];
  99.     next = [nextForm intValueAt:0];
  100.     previous = [previousForm intValueAt:0];
  101.     
  102.     if( here == 0)
  103.         {
  104.         if(NXRunAlertPanel("Alert!", 
  105.             "Event 0 is an important header location. "
  106.             "Are you SURE you want to overwrite it?",
  107.             "Overwrite","Cancel", NULL ) == 0)
  108.             return self;
  109.         }
  110.         
  111.     if( here < 0)
  112.         {
  113.         NXRunAlertPanel("File Write Error", "Sorry, you can't "
  114.             "write to negative event numbers.", 
  115.             "Ahh..", NULL,NULL);
  116.         return self;
  117.         }
  118.     
  119.     if( vHere != here && NXRunAlertPanel("Event Mismatch in Writing",
  120.                 "The event you read from is not the same "
  121.                 "as the one you are writing to. "
  122.                 "Are you SURE you want to do this?",
  123.                 "Cancel","Write",NULL) == 1)
  124.         return self;
  125.             
  126.     [ev setMessage     : (char *) [messageForm stringValueAt:0]];
  127.     [ev setShowMessage:     [messageButton        state]];
  128.     switch( [alarmSoundRadioMatrix selectedRow] )
  129.         {
  130.         case 0:    // sound
  131.             [ev setAlarmAction: 1];
  132.             break;
  133.         case 1: // runCommand
  134.             [ev setAlarmAction: 3];
  135.             break;
  136.         case 2: // nada
  137.             [ev setAlarmAction: 0];
  138.         break;
  139.         }
  140.     [ev setAlarmSound : (char *) [alarmSoundForm stringValueAt:0]];
  141.  
  142.     [ev setTime:    [self    getDate: self]];
  143.         
  144.     if( [anniversaryForm intValueAt:0] > 99)
  145.         {
  146.         NXRunAlertPanel("Anniversary Overload",
  147.             "Due to a design error that cannot be fixed until "
  148.             "Version 2.0, you cannot have a reoccuring event "
  149.             "of more than 99 intervals.","OK",NULL,NULL);
  150.         [anniversaryForm selectTextAt: 0];
  151.         return nil;
  152.         }
  153.         
  154.     vAnniv = ([anniversaryRadioMatrix selectedCol] +1 ) * 100;    
  155.  
  156.     [ev setAnniversary:    ([anniversaryButton state]
  157.                 ? ([anniversaryForm intValueAt:0] + vAnniv)
  158.                 : 0) ];
  159.  
  160.     [ev setDestroy:        0];    // Destroy not supported after v0.9.2
  161.  
  162.     [ev setSnoozeNo:        ([snoozeButton state]
  163.                 ? [snoozeNoForm intValueAt:0]
  164.                 : 0)];
  165.     [ev setSnoozeInt:     ([snoozeButton state]    
  166.                 ? [snoozeIntForm intValueAt:0]
  167.                 : 0)];
  168.     [ev setPriority:     ([priorityRadioMatrix selectedCol]*50)];
  169.     [ev setNext : next];
  170.     [ev setPrevious : previous];
  171.  
  172.  
  173.     if( ! [global guru] && (timeCompare(&vNow, [ev time]) != 0))
  174.         {
  175.         if(NXRunAlertPanel( "Warning",
  176.                 "You have changed the date or time, use "
  177.                 "re-insert to put the event back in the "
  178.                 "queue. Insert will duplicate the "
  179.                 "event.","Insert","Cancel",NULL) == 0)
  180.             return self;
  181.         }
  182.         
  183.     [ev writeEvent : here];
  184.  
  185.     [hereForm selectTextAt:0];
  186.     if( ![global guru])    /* If we're not a guru, then update */
  187.         [cassandra queueDidChange:self];
  188.  
  189.     // The window has been saved
  190.     [self setDocEdited:    FALSE];
  191.  
  192.     return self;
  193. }
  194.  
  195.  
  196. - murderEvent : sender
  197. {
  198.     int here, next;
  199.         
  200.     here = [hereForm intValueAt:0];
  201.     [ev readEvent: here];
  202.     next = [ev next];
  203.     
  204.     if( [ev present] <= 0)
  205.         {
  206.         NXRunAlertPanel("Delete Error",
  207.             "Cannot reset/cancel events 0 or below.", 
  208.             "Oh well...",NULL,NULL);
  209.         return self;
  210.         }
  211.         
  212.     if( NXRunAlertPanel("Warning",
  213.             "This will reset this event. "
  214.             "Are you sure you want to do this?",
  215.             "Reset","Cancel",NULL) == 0)
  216.         return self;
  217.         
  218.     here = [ev murderEvent : here];
  219.     
  220.     // If the event was truly deleted when canceled, then we will 
  221.     // read the next event, otherwise we will read the event 
  222.     // EFileLink returned by murderEvent
  223.     if( here != -1)
  224.         next = here;
  225.     
  226.     [hereForm setIntValue : next at: 0];
  227.     [self readEvent:self];
  228.  
  229.     [cassandra queueDidChange:self];
  230.  
  231.         return self;
  232. }
  233.  
  234. - deleteEvent:sender
  235. {
  236.     int here, next;
  237.         
  238.     here = [hereForm intValueAt:0];
  239.     [ev readEvent: here];
  240.     next = [ev next];
  241.     
  242.     if( [ev present] <= 0)
  243.         {
  244.         NXRunAlertPanel("Delete Error",
  245.                 "Cannot delete events 0 or below.",
  246.                 "Oh well...",NULL,NULL);
  247.         return self;
  248.         }
  249.         
  250.     if( NXRunAlertPanel("Warning", 
  251.             "This will permanently delete this event. "
  252.             "Are you sure you want to do this?", 
  253.             "Delete","Cancel",NULL) == 0)
  254.         return self;
  255.         
  256.     [ev deleteEvent : here];
  257.     
  258.     [hereForm setIntValue : next at: 0];
  259.     [self readEvent:self];
  260.  
  261.     [cassandra queueDidChange:self];
  262.         return self;
  263. }
  264.  
  265.  
  266. - insertEvent:sender
  267. {
  268.     if( ![global guru])
  269.         {
  270.         if( NXRunAlertPanel("Warning", 
  271.                 "You really should use the Add Event panel. "
  272.                 "Using insert on an already existing "
  273.                 "record will duplicate it.",
  274.                 "Insert","Cancel",NULL) == 0)
  275.             return self;
  276.         }
  277.  
  278.     [super insertEvent : self];
  279.     if( ![global guru])
  280.         [cassandra queueDidChange:self];
  281.     return self;
  282. }
  283.  
  284.  
  285. - reinsertEvent:sender
  286. {
  287.     int here, vAnniv;
  288.     
  289.     here = [hereForm intValueAt:0];
  290.     if( vHere != here)
  291.         {
  292.         if(NXRunAlertPanel("Event Mismatch on Re-insert",
  293.                 "The event you read from is not the same "
  294.                 "as the one you are reinserting into. "
  295.                 "This could mess things up PRETTY BADLY. "
  296.                 "Are you SURE you want to do this?",
  297.                 "Re-insert","Cancel",NULL) == 0)
  298.             return self;
  299.         }
  300.  
  301.     if(here <= 0)
  302.         {
  303.         NXRunAlertPanel("Reinsert Error",
  304.             "Cannot reinsert events 0 or below.", 
  305.             "Oh well...",NULL,NULL);
  306.         return self;
  307.         }
  308.         
  309.     if( [self dateFinished: self] == NULL)
  310.         return self;
  311.  
  312.     [ev readEvent: here];
  313.     [ev deleteEvent : here];
  314.         
  315.     [ev setMessage     : (char *) [messageForm stringValueAt:0]];
  316.     [ev setShowMessage:    [messageButton        state]];
  317.     switch( [alarmSoundRadioMatrix selectedRow] )
  318.         {
  319.         case 0:    // sound
  320.             [ev setAlarmAction: 1];
  321.             break;
  322.         case 1: // runCommand
  323.             [ev setAlarmAction: 3];
  324.             break;
  325.         case 2: // nada
  326.             [ev setAlarmAction: 0];
  327.         break;
  328.         }
  329.     [ev setAlarmSound : (char *) [alarmSoundForm stringValueAt:0]];
  330.     
  331.     [ev setTime:    [self    getDate: self]];    
  332.  
  333.     if( [anniversaryForm intValueAt:0] > 99)
  334.         {
  335.         NXRunAlertPanel("Anniversary Overload",
  336.             "Due to a design error that cannot be fixed until "
  337.             "Version 1.1, you cannot have a reoccuring event of "
  338.             "more than 99 intervals.","OK",NULL,NULL);
  339.         [anniversaryForm selectTextAt: 0];
  340.         return nil;
  341.         }
  342.         
  343.     vAnniv = ([anniversaryRadioMatrix selectedCol] +1 ) * 100;    
  344.  
  345.     [ev setAnniversary:     ([anniversaryButton state]
  346.                 ? ([anniversaryForm intValueAt:0]  + vAnniv)
  347.                 : 0) ];
  348.  
  349.     [ev setDestroy:        0];    // Destroy not supported after v0.9.2
  350.  
  351.     [ev setSnoozeNo:     ([snoozeButton state]
  352.                 ? [snoozeNoForm intValueAt:0]
  353.                 : 0)];
  354.     [ev setSnoozeInt:     ([snoozeButton state]    
  355.                 ? [snoozeIntForm intValueAt:0]
  356.                 : 0)];
  357.     [ev setPriority:     ([priorityRadioMatrix selectedCol]*50)];
  358.     
  359.     [ev insertEvent];
  360.  
  361.     [hereForm setIntValue :[ev present] at: 0];
  362.     [self readEvent:self];
  363.  
  364.     if( ![global guru])
  365.         [cassandra queueDidChange:self];
  366.     return self;
  367. }
  368.  
  369. - nextLink : sender
  370. {
  371.     int here;
  372.  
  373.     here = [nextForm intValueAt:0];
  374.     if( here == 0 && [global guru] == NO)
  375.         {
  376.         NXBeep();
  377.         return self;
  378.         }
  379.     [hereForm setIntValue: here at:0];
  380.     [self readEvent:self];
  381.     return self;
  382. }
  383.  
  384. - previousLink : sender
  385. {
  386.     int here;
  387.     
  388.     here = [previousForm intValueAt:0];
  389.     if( here == 0 && [global guru] == NO)
  390.         {
  391.         NXBeep();
  392.         return self;
  393.         }
  394.         
  395.     [hereForm setIntValue: here at:0];
  396.     [self readEvent:self];
  397.     return self;
  398. }
  399.  
  400. - nextEvent : sender
  401. {
  402.     int here;
  403.     
  404.     here = [hereForm intValueAt:0]+1;
  405.     [hereForm setIntValue: here at:0];
  406.     [self readEvent:self];
  407.     return self;
  408. }
  409.  
  410. - previousEvent : sender
  411. {
  412.     int here;
  413.     
  414.     here = [hereForm intValueAt:0] -1 ;
  415.     [hereForm setIntValue: here at:0];
  416.     [self readEvent:self];
  417.     return self;
  418. }
  419. @end
  420.